home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus Special 16 / AMIGAplus Sonderheft 16 (1998)(ICP)(DE)[!].iso / pd / anwendungen / rtgmaster_dev / includes / stormc / rtgmaster / rtgtcpip.h < prev   
C/C++ Source or Header  |  1997-10-23  |  7KB  |  255 lines

  1. #ifndef RTGMASTER_RTGTCPIP_H
  2. #define RTGMASTER_RTGTCPIP_H 1
  3.  
  4. #ifndef LARGE_BUFSIZE
  5. #define LARGE_BUFSIZE (12 * 1024)
  6. #endif
  7.  
  8. #ifndef GARBAGE_SPACE
  9. #define GARBAGE_SPACE 32
  10. #endif
  11.  
  12. #ifndef  NBBY
  13. #define NBBY    8                       /* number of bits in a byte */
  14. #endif
  15.  
  16. #ifndef FD_SETSIZE
  17. #define FD_SETSIZE      64
  18. #endif
  19.  
  20. #ifndef INVALID_SOCKET
  21. #define INVALID_SOCKET -1
  22. #endif
  23.  
  24. #ifndef SYS_TYPES_H
  25. #ifndef fd_mask
  26. typedef long    fd_mask;
  27. #endif
  28. #endif
  29.  
  30. #ifndef NFDBITS
  31. #define NFDBITS (sizeof(fd_mask) * NBBY) /* bits per mask */
  32. #endif
  33.  
  34. #ifndef howmany
  35. #define howmany(x, y)   (((x)+((y)-1))/(y))
  36. #endif
  37.  
  38. #ifndef SYS_TYPES_H
  39. typedef struct fd_set {
  40.         fd_mask fds_bits[howmany(FD_SETSIZE, NFDBITS)];
  41. } fd_set;
  42.  
  43. typedef unsigned char   u_char;
  44. typedef unsigned short  u_short;
  45. typedef unsigned int    u_int;
  46. typedef unsigned long   u_long;
  47. typedef unsigned short  ushort;         /* Sys V compatibility */
  48. typedef char*           caddr_t;        /* core address */
  49. typedef unsigned long   dev_t;
  50. typedef unsigned long   ino_t;
  51. typedef long            off_t;
  52.  
  53. #define SYS_TYPES_H
  54.  
  55. // Sort of a hack (why i did this : See below...)
  56. // (Sys/types.h differs, according to, if we have
  57. // only SAS/C installed or SAS/C + AmiTCP includes.
  58. // This code should not give an error, anyways, which
  59. // version of sys/types.h we have installed. So i did
  60. // all sys/types.h stuff from SAS/C + AmiTCP HERE and
  61. // hindered sys/types.h to be included :) ...
  62.  
  63.  
  64. #endif
  65.  
  66. #ifndef FD_SET
  67. #define FD_SET(n, p)    ((p)->fds_bits[(n)/NFDBITS] |= (1 << ((n) % NFDBITS)))
  68. #endif
  69.  
  70. #ifndef FD_CLR
  71. #define FD_CLR(n, p)    ((p)->fds_bits[(n)/NFDBITS] &= ~(1 << ((n) % NFDBITS)))
  72. #endif
  73.  
  74. #ifndef FD_ISSET
  75. #define FD_ISSET(n, p)  ((p)->fds_bits[(n)/NFDBITS] & (1 << ((n) % NFDBITS)))
  76. #endif
  77.  
  78. #ifndef FD_ZERO
  79. #define FD_ZERO(p)      bzero((char *)(p), sizeof(*(p)))
  80. #endif
  81.  
  82. #ifndef SOCK_STREAM
  83. #define SOCK_STREAM     1               /* stream socket */
  84. #endif
  85.  
  86. #ifndef SOCK_DGRAM
  87. #define SOCK_DGRAM      2               /* datagram socket */
  88. #endif
  89.  
  90. struct RTG_Buff
  91. {
  92.  char sock[12][1024];
  93.  int num[12];
  94.  int in_size;
  95.  int out_size;
  96. };
  97.  
  98. // Sort of a HACK that we do not get a collision
  99. // with AmiTCP includes, if installed... :)
  100. // (most of the stuff in this includefile is
  101. // only needed to COMPILE rtgmaster.library itself,
  102. // not for the USAGE of the library, so do not wonder,
  103. // if it is missing in the ASM part... the TCP/IP
  104. // part of rtgmaster is written in C, contrary to
  105. // the rest of rtgmaster (which is written in ASM)
  106.  
  107. #ifndef NET_IN_H
  108. #define NET_IN_H
  109.  
  110. #define IN_H XXX - compatibility
  111.  
  112. /*
  113.  * Macros for network/external number representation conversion.
  114.  */
  115. #ifndef ntohl
  116. #define ntohl(x)        (x)
  117. #define ntohs(x)        (x)
  118. #define htonl(x)        (x)
  119. #define htons(x)        (x)
  120.  
  121. #define NTOHL(x)        (x)
  122. #define NTOHS(x)        (x)
  123. #define HTONL(x)        (x)
  124. #define HTONS(x)        (x)
  125. #endif
  126.  
  127. /*
  128.  * Constants and structures defined by the internet system,
  129.  * Per RFC 790, September 1981.
  130.  */
  131.  
  132. /*
  133.  * Protocols
  134.  */
  135. #define IPPROTO_IP              0               /* dummy for IP */
  136. #define IPPROTO_ICMP            1               /* control message protocol */
  137. #define IPPROTO_GGP             3               /* gateway^2 (deprecated) */
  138. #define IPPROTO_TCP             6               /* tcp */
  139. #define IPPROTO_EGP             8               /* exterior gateway protocol */
  140. #define IPPROTO_PUP             12              /* pup */
  141. #define IPPROTO_UDP             17              /* user datagram protocol */
  142. #define IPPROTO_IDP             22              /* xns idp */
  143. #define IPPROTO_TP              29              /* tp-4 w/ class negotiation */
  144. #define IPPROTO_EON             80              /* ISO cnlp */
  145.  
  146. #define IPPROTO_RAW             255             /* raw IP packet */
  147. #define IPPROTO_MAX             256
  148.  
  149.  
  150. /*
  151.  * Local port number conventions:
  152.  * Ports < IPPORT_RESERVED are reserved for
  153.  * privileged processes (e.g. root).
  154.  * Ports > IPPORT_USERRESERVED are reserved
  155.  * for servers, not necessarily privileged.
  156.  */
  157. #define IPPORT_RESERVED         1024
  158. #define IPPORT_USERRESERVED     5000
  159.  
  160. /*
  161.  * Internet address (a structure for historical reasons)
  162.  */
  163. struct in_addr {
  164.         u_long s_addr;
  165. };
  166.  
  167. /*
  168.  * Definitions of bits in internet address integers.
  169.  * On subnets, the decomposition of addresses to host and net parts
  170.  * is done according to subnet mask, not the masks here.
  171.  */
  172. #define IN_CLASSA(i)            (((long)(i) & 0x80000000) == 0)
  173. #define IN_CLASSA_NET           0xff000000
  174. #define IN_CLASSA_NSHIFT        24
  175. #define IN_CLASSA_HOST          0x00ffffff
  176. #define IN_CLASSA_MAX           128
  177.  
  178. #define IN_CLASSB(i)            (((long)(i) & 0xc0000000) == 0x80000000)
  179. #define IN_CLASSB_NET           0xffff0000
  180. #define IN_CLASSB_NSHIFT        16
  181. #define IN_CLASSB_HOST          0x0000ffff
  182. #define IN_CLASSB_MAX           65536
  183.  
  184. #define IN_CLASSC(i)            (((long)(i) & 0xe0000000) == 0xc0000000)
  185. #define IN_CLASSC_NET           0xffffff00
  186. #define IN_CLASSC_NSHIFT        8
  187. #define IN_CLASSC_HOST          0x000000ff
  188.  
  189. #define IN_CLASSD(i)            (((long)(i) & 0xf0000000) == 0xe0000000)
  190. #define IN_MULTICAST(i)         IN_CLASSD(i)
  191.  
  192. #define IN_EXPERIMENTAL(i)      (((long)(i) & 0xe0000000) == 0xe0000000)
  193. #define IN_BADCLASS(i)          (((long)(i) & 0xf0000000) == 0xf0000000)
  194.  
  195. #define INADDR_ANY              (u_long)0x00000000
  196. #define INADDR_BROADCAST        (u_long)0xffffffff      /* must be masked */
  197. #if !defined(KERNEL) || defined(AMITCP)
  198. #define INADDR_NONE             0xffffffff              /* -1 return */
  199. #endif
  200.  
  201. #define IN_LOOPBACKNET          127                     /* official! */
  202.  
  203. /*
  204.  * Socket address, internet style.
  205.  */
  206. struct sockaddr_in {
  207.         u_char  sin_len;
  208.         u_char  sin_family;
  209.         u_short sin_port;
  210.         struct  in_addr sin_addr;
  211.         char    sin_zero[8];
  212. };
  213.  
  214. /*
  215.  * Structure used to describe IP options.
  216.  * Used to store options internally, to pass them to a process,
  217.  * or to restore options retrieved earlier.
  218.  * The ip_dst is used for the first-hop gateway when using a source route
  219.  * (this gets put into the header proper).
  220.  */
  221. struct ip_opts {
  222.         struct  in_addr ip_dst;         /* first hop, 0 w/o src rt */
  223.         char    ip_opts[40];            /* actually variable in size */
  224. };
  225.  
  226. /*
  227.  * Options for use with [gs]etsockopt at the IP level.
  228.  * First word of comment is data type; bool is stored in int.
  229.  */
  230. #define IP_OPTIONS      1       /* buf/ip_opts; set/get IP per-packet options */
  231. #define IP_HDRINCL      2       /* int; header is included with data (raw) */
  232. #define IP_TOS          3       /* int; IP type of service and precedence */
  233. #define IP_TTL          4       /* int; IP time to live */
  234. #define IP_RECVOPTS     5       /* bool; receive all IP options w/datagram */
  235. #define IP_RECVRETOPTS  6       /* bool; receive IP options for response */
  236. #define IP_RECVDSTADDR  7       /* bool; receive IP dst addr w/datagram */
  237. #define IP_RETOPTS      8       /* ip_opts; set/get IP per-packet options */
  238.  
  239. #endif /* !IN_H */
  240.  
  241.  
  242. struct RTG_Socket
  243. {
  244.     int s;   // The TCP/IP Socket
  245.     int num; // number of open connections,
  246.              // including the server itself
  247.     struct RTG_Socket *list; // List of connections of a server
  248.     fd_set input_set, output_set, exc_set; // The sets
  249.     struct sockaddr_in peer;
  250.     int mode;
  251.     int server;
  252. };
  253.  
  254. #endif
  255.